<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/login.css" rel="stylesheet" />

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">找回密码</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>邮箱</label>
					<input id='email' type="email" class="mui-input-clear mui-input" placeholder="请输入注册邮箱">
				</div>
				<div class="mui-input-row">
					<label>验证码</label>

					<input id='vcode' style="width: 45%;float: left;" type="email" class="mui-input-clear mui-input" placeholder="请输入验证码">
					<input type="button" style="width: 30%;float: left;" id='sendMail' value="获取验证码">

				</div>
				<div class="mui-input-row">
					<label>新密码</label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入新密码">
				</div>
				<div class="mui-input-row">
					<label>确认</label>
					<input id='re-password' type="password" class="mui-input-clear mui-input" placeholder="请确认新密码">
				</div>
			</form>
			<div class="mui-content-padded">
				<button class="mui-btn mui-btn-block mui-btn-primary" id="resetPwd">提交</button>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script type="text/javascript" src="../js/const.js"></script>
		<script type="text/javascript" src="../js/request.js"></script>
		<script type="text/javascript" src="../js/user_service.js"></script>
		<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
		<script>
			(function($, doc) {
				$.init();
				$.plusReady(function() {
					var sendButton = doc.getElementById('sendMail');
					var resetPwdButton = doc.getElementById('resetPwd');
					var emailBox = doc.getElementById('email');
					var sendMailBox = doc.getElementById('sendMail');
					var password = doc.getElementById('password');
					var rePassword = doc.getElementById('re-password');
					var vcode = doc.getElementById('vcode');

					//获取验证码按钮事件
					sendButton.addEventListener('tap', function() {

						app.sendEmail(emailBox.value, sendMailBox, function(err, info) {
							plus.nativeUI.toast(err || info);
						});
					}, false);

					//提交按钮事件

					resetPwdButton.addEventListener('tap', function() {

						app.resetPassword(password.value, rePassword.value, emailBox.value, vcode.value, function(err) {

							if(err) {
								plus.nativeUI.toast(err);
								return;
							}
							plus.nativeUI.toast("密码重置成功");
							setInterval(function() { //等待用户看清提示，关闭窗口
								mui.currentWebview.close();
							}, 2000);

						});
					}, false);
				});
			}(mui, document));
			var countdown = 60;

			function settime(val) {
				if(countdown == 0) {
					val.removeAttribute("disabled");
					val.value = "获取验证码";
					countdown = 60;
					return false
				} else {
					val.setAttribute("disabled", true);
					val.value = "重新发送(" + countdown + ")";
					countdown--;
				}
				setTimeout(function() {
					settime(val)
				}, 1000)
			}
		</script>
	</body>

</html>